home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / devBlockDevice.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-18  |  5.9 KB  |  194 lines

  1. /* 
  2.  * devBlockDevice.c --
  3.  *
  4.  *    Routines supporting the interface to Sprite block devices.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifdef notdef
  17. static char rcsid[] = "$Header: /sprite/src/kernel/dev/RCS/devBlockDevice.c,v 1.1 89/05/01 15:32:32 mendel Exp Locker: brent $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20.  
  21. #include "sprite.h"
  22. #include "user/fs.h"
  23. #include "devBlockDevice.h"
  24. #include "devFsOpTable.h"
  25. #include "sync.h"
  26. #include "boot.h"
  27. #include "machMon.h"
  28.  
  29. /*
  30.  *----------------------------------------------------------------------
  31.  *
  32.  * Dev_BlockDeviceAttach --
  33.  *
  34.  *    Build data structures necessary for accessing a block device.
  35.  *    This routine interprets the type field of the Fs_Device structure
  36.  *    and calls the appropriate attach routine. 
  37.  *
  38.  * Results:
  39.  *    A pointer to a DevBlockDeviceHandle structure for the device. 
  40.  *    NIL if the device can not be attached.
  41.  *
  42.  * Side effects:
  43.  *    Device dependent.
  44.  *
  45.  *----------------------------------------------------------------------
  46.  */
  47. DevBlockDeviceHandle *
  48. Dev_BlockDeviceAttach(devicePtr)
  49.     Fs_Device    *devicePtr;    /* The device to attach. */
  50. {
  51.  
  52.     /*
  53.      * If type is out of range or the device type as no block IO 
  54.      * capabilities then give up. Otherwise we let the Device Attach
  55.      * procedure file the device.
  56.      */
  57.     return ((devFsOpTable[0].blockDevAttach)(devicePtr));
  58. }
  59.  
  60.  
  61. /*
  62.  *----------------------------------------------------------------------
  63.  *
  64.  * Dev_BlockDeviceRelease --
  65.  *
  66.  *    Release an attached block device. Resources held by the device 
  67.  *    should be freed.
  68.  *
  69.  * Results:
  70.  *    A Sprite return Status specifying it the device could be releases.
  71.  *
  72.  * Side effects:
  73.  *    Device dependent.
  74.  *
  75.  *----------------------------------------------------------------------
  76.  */
  77. ReturnStatus
  78. Dev_BlockDeviceRelease(blockDevHandlePtr)
  79.      DevBlockDeviceHandle
  80.         *blockDevHandlePtr;  /* Handle of the device to releaes */
  81. {
  82.  
  83. }
  84.  
  85. /*
  86.  * The following structure and routines are used to implement the routine
  87.  * Dev_BlockDeviceIOSync.
  88.  * The arguments to Dev_BlockDeviceIOSync are stored in a SyncCmdBuf on 
  89.  * the caller's stack and  Dev_BlockDeviceIO is called. The call back function
  90.  * syncDoneProc fills in the OUT arguments are wakes the caller.
  91.  *
  92.  */
  93. typedef struct SyncCmdBuf {
  94.     Sync_Semaphore mutex;      /* Lock for synronizing updates of 
  95.                    * this structure with the call back 
  96.                    * function. */
  97.     Sync_Condition wait;      /* Condition valued used to wait for
  98.                    * callback. */
  99.     Boolean      done;          /* Is the operation finished or not? */
  100.     int      amountTransferred;       /* Number of bytes transferred according
  101.                    * to the call back. */
  102.     ReturnStatus status;       /* Operation return status according to 
  103.                    * call back. */
  104. } SyncCmdBuf;
  105.  
  106. /*
  107.  *----------------------------------------------------------------------
  108.  *
  109.  * syncDoneProc --
  110.  *
  111.  *    This procedure is called when a sync block command started by 
  112.  *    Dev_BlockDeviceIO finished. It's calling sequence is 
  113.  *    defined by the call back caused by the Dev_BlockDeviceIO routine.
  114.  *
  115.  * Results:
  116.  *    None.
  117.  *
  118.  * Side effects:
  119.  *    SyncCmdBuf is filled in and a wakeup is broadcast.
  120.  *
  121.  *----------------------------------------------------------------------
  122.  */
  123.  
  124. static void
  125. syncDoneProc(requestPtr, status, amountTransferred)
  126.     DevBlockDeviceRequest    *requestPtr;
  127.     ReturnStatus status;
  128.     int    amountTransferred;
  129. {
  130.     SyncCmdBuf    *syncCmdDataPtr = (SyncCmdBuf *) (requestPtr->clientData);
  131.     /*
  132.      * A pointer to a SyncCmdBuf is passed as the clientData to this call.
  133.      * Lock the structure, fill in the return values and wake up the
  134.      * initiator.
  135.      */
  136.     MASTER_LOCK(&syncCmdDataPtr->mutex);
  137.     syncCmdDataPtr->status = status;
  138.     syncCmdDataPtr->amountTransferred = amountTransferred;
  139.     syncCmdDataPtr->done = TRUE;
  140.     Sync_MasterBroadcast(&syncCmdDataPtr->wait);
  141.     MASTER_UNLOCK(&syncCmdDataPtr->mutex);
  142.     return;
  143. }
  144.  
  145. /*
  146.  *----------------------------------------------------------------------
  147.  *
  148.  * Dev_BlockDeviceIOSync --
  149.  *
  150.  *    Perform a block IO request for the specified device and wait 
  151.  *    for completion.
  152.  *
  153.  * Results:
  154.  *    SUCCESS if operation is successful completed. 
  155.  *    A Sprite error code otherwise.
  156.  *
  157.  * Side effects:
  158.  *    Device specific block IO done.
  159.  *----------------------------------------------------------------------
  160.  */
  161. ReturnStatus 
  162. Dev_BlockDeviceIOSync(blockDevHandlePtr, requestPtr,amountTransferredPtr)
  163.     DevBlockDeviceHandle
  164.         *blockDevHandlePtr;  /* Handle of the device to operate on. */
  165.     DevBlockDeviceRequest 
  166.         *requestPtr;         /* Request to block IO device. */
  167.     int    *amountTransferredPtr;          /* Area to store number of bytes
  168.                       * transferred. May be NIL. */
  169. {
  170.     ReturnStatus status;
  171.     SyncCmdBuf     syncCmdData;
  172.     Mach_MonPrintf("Read from 0x%x offset %d size %d to 0x%x\n", blockDevHandlePtr, requestPtr->startAddress,
  173.             requestPtr->bufferLen, requestPtr->buffer);
  174.     requestPtr->clientData = (ClientData) &syncCmdData;
  175.     requestPtr->doneProc = syncDoneProc;
  176.     Sync_SemInitDynamic((&syncCmdData.mutex),"BlockSyncCmdMutex");
  177.     syncCmdData.done = FALSE;
  178.     syncCmdData.amountTransferred = 0;
  179.     status = Dev_BlockDeviceIO(blockDevHandlePtr, requestPtr);
  180.     if (status == SUCCESS) {
  181.     MASTER_LOCK((&syncCmdData.mutex));
  182.     while (syncCmdData.done == FALSE) { 
  183.         boot_Poll();
  184.     }
  185.     MASTER_UNLOCK((&syncCmdData.mutex));
  186.     status = syncCmdData.status;
  187.     } 
  188.     if (amountTransferredPtr != (int *) NIL) { 
  189.     *amountTransferredPtr = syncCmdData.amountTransferred;
  190.     }
  191.     Mach_MonPrintf("Done %x\n", status);
  192.     return (status);
  193. }
  194.